package com.skynet.supervision.utils.functional;

import com.skynet.supervision.exceptions.CheckedException;

import java.util.function.Function;

@FunctionalInterface
public interface ThrowableFunction<T, R, E extends Throwable> {
    R apply(T t) throws E, CheckedException;

    default Function<T, R> toFunction() {
        return in -> {
            try {
                return ThrowableFunction.this.apply(in);
            } catch (Throwable e) {
                FuncUtils.uncheckedThrow(e);
            }
            throw new RuntimeException("unreachable code!");
        };
    }
}
